// pages/detail/detail.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    txt: [],
    cintx: [],
    perImgSrc: [],
    shaidan:[],
    otherlist: [],
    id:[],
    condetail:[],
    anli:[],
    latitude: [],
    longitude: [],
    showModal: false,
     mobile:[],
    gift: '送意大利品牌量身定制衬衫一款价值880元',
    detailComTxt: '很喜欢拍摄的风格，服务态度很好，很有耐心，经验丰富，拍摄的效果很好。',
    allanli:true,
    allshaidan:true,
  },
  savetell:function(e){
    var that = this;
    var tellp = e.detail.value;

    console.log(e)
    that.setData({ mobile: tellp })
  },
  tianjia: function (e) {
    var that = this;
    var inp = e.detail.value;
    

    that.setData({ cintx: inp })
 
    var inputCode = that.data.cintx;
  
    if (inputCode.length <= 0) {
      wx.showToast({
        title: '请输入验证码',
        icon: 'fail',
        duration: 2000
      })
    } else if (inputCode != that.data.txt) {
      wx.showToast({
        title: '输入验证码错误',
        icon: 'fail',
        duration: 2000
      })
      that.createCode();//刷新验证码  
    } else {
      wx.showToast({
        title: '成功',
        icon: 'success',
        duration: 2000,
       
      })
      var openid = app.globalData.openid;
      var id=that.data.id;
      console.log(that.data)
      var mobile=that.data.mobile;
      console.log(6666666)
      console.log(openid)
      console.log(id)
      console.log(mobile)
      wx.request({
        url: 'http://xcx.wedpl.com/index.php?g=Home&m=Index&a=appointment',
        data: { object_id: id, mobile: mobile, opentionid: openid },
        method:'post',
        
        header: {
          'content-type': 'application/x-www-form-urlencoded'
        },
       
        success(res){
          console.log(res)
        }


      })
      that.setData({
        showModal: false
      })
    }
  },
  createCode: function () {
    var that = this;
    var code = "";
    var codeLength = 6;//验证码的长度  

    var selectChar = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];//所有候选组成验证码的字符，当然也可以用中文的  

    for (var i = 0; i < codeLength; i++) {
      var charIndex = Math.floor(Math.random() * 36);
      console.log(charIndex)
      code += selectChar[charIndex];
    }
    //alert(code);
    that.setData({ txt: code })
  },

  onLoad: function (options) {
    console.log(options)
    
    var that = this;
    that.setData({ id:options.id}),
    //调用应用实例的方法获取全局数据
    app.getUserInfo(function (userInfo) {
      //更新数据
      that.setData({
        userInfo: userInfo
      })
    })
    that.getinfo();
   that.getshaidan();
   that.seeother();
   
  },
checklocation:function(){
  var that=this;
  var latitude = that.data.latitude;
  var longitude = that.data.longitude;
  console.log(latitude)
  console.log(longitude)
  wx.openLocation({
    latitude: latitude,
    longitude: longitude,
    scale: 28
  })
},
  showDialogBtn1: function () {
    wx.makePhoneCall({
      phoneNumber: '1340000' //仅为示例，并非真实的电话号码
    })
  },
  setLoading: function (e) {
    var duanziInfoBefore = this.data.anli
    var that = this
    var id=that.data.id;
    wx.showToast({ //期间为了显示效果可以添加一个过度的弹出框提示“加载中”  
      title: '加载中',
      icon: 'loading',
      duration: 200
    })
    that.setData({allanli:false})
    wx.request({
      url: 'http://xcx.wedpl.com/index.php?g=Home&m=Index&a=get_remaining&id='+id,
      method: 'GET',
      success: function (res) {
        console.log(res)
        console.log(duanziInfoBefore.concat(res.data)) //打印拼接之后数据  
        that.setData({
       
          anli: duanziInfoBefore.concat(res.data),
       
        })
      }
    })
  }  ,
  getshaidan:function(){
      var that=this;
      var object_id=that.data.id;
      var shaidan=[];
     
      wx.request({
        url: 'http://xcx.wedpl.com/index.php?g=Home&m=Index&a=return_assess&object_id='+object_id,
        method:"get",
        header:{
          "content-type":"application/JSON"
        },
        success(res){
         
          shaidan = res.data;
       
             that.setData({
               shaidan:shaidan,
               })
        }
      })
        console.log(1222222)
          console.log(that.data.shaidan) 
  },
  moreshaidan:function(e){
    
    var that = this
    var id = that.data.id;
    var bshaidan = that.data.shaidan;
    var nshaidan=[];
    wx.showToast({ //期间为了显示效果可以添加一个过度的弹出框提示“加载中”  
      title: '加载中',
      icon: 'loading',
      duration: 200
    })
    that.setData({ allshaidan: false })
    wx.request({
      url: 'http://xcx.wedpl.com/index.php?g=Home&m=Index&a=get_remaining_assess&object_id=' + id,
      method: 'GET',
      header: {
        "content-type": "application/JSON"
      },
      success: function (res) {
        console.log(55555)
        console.log(res)
        nshaidan=res.data;
        console.log(nshaidan)
        nshaidan.concat(that.data.shaidan)
      
         //打印拼接之后数据  

         console.log(nshaidan)
        that.setData({

           shaidan:nshaidan

        })
      }
    })
  },
  seeother:function(){
  var that=this;
  var id=that.data.id;
  wx.request({
    url: 'http://xcx.wedpl.com/index.php?g=Home&m=Index&a=get_other_goods',
    method:"get",
    header:{
      "content-type":"application/json"
    },
    success(res){
      var otherlist=res.data
      that.setData({ otherlist: otherlist})
    }
  })
  },
  getinfo:function(){
     var that=this;
     var id=that.data.id;
     console.log(1111111111111111);
     console.log(id);
     wx.request({
       url: 'http://xcx.wedpl.com/index.php?g=Home&m=Index&a=memarydetail&id='+id,
       method: 'get',
       header: {
         'content-type': 'application/json'
       },
       success(res) {
        console.log(res)
         var ress = res.data;
         var latitude = res.data[0].post_keywords[0];
        var condetail=res.data[0];
         var longitude = res.data[0].post_keywords[1];
         var anli = [];
        
         for(var k in ress)
         { 
           if(ress[k].id)
             anli[k]=ress[k];            
         } 
         anli.splice(0,1)
         
         that.setData({
           latitude: latitude,
           longitude: longitude,
           condetail:condetail,
           anli: anli
         })
         console.log(that.data.latitude);
         console.log(anli);
       }
     })
  },
  //弹窗
  showDialogBtn3: function () {
    this.setData({
      showModal: true
    })
    this.createCode();
  },
  /**
   * 弹出框蒙层截断touchmove事件
   */
  preventTouchMove: function () {
  },
  /**
   * 隐藏模态对话框
   */
  hideModal: function () {
    this.setData({
      showModal: false
    });
  },
  /**
   * 对话框取消按钮点击事件
   */
  onCancel: function () {
    this.hideModal();
  },
  /**
   * 对话框确认按钮点击事件
   */
  onConfirm: function () {
    this.hideModal();
  }
})